package com.project.restaurant.common.config;


import com.project.restaurant.common.interceptor.AccessLimitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SpringMvcExtendConfig implements WebMvcConfigurer {

    @Autowired
    AccessLimitInterceptor accessLimitInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //访问限制
        InterceptorRegistration accessLimitInterceptorId = registry.addInterceptor(accessLimitInterceptor);
        accessLimitInterceptorId.addPathPatterns(
                "/user/**",
                "/order/**"
        );
        accessLimitInterceptorId.excludePathPatterns(
                "/user/login/**",
                "/user/register/**"
        );
        accessLimitInterceptorId.order(0);
    }
}
